<!-- 收发电管理>待收来电 -->
<template>
	<view>
		<van-pull-refresh v-model="refreshing" @refresh="onRefresh">
			<van-empty description="暂无数据" v-show="emptyData"/>
			<van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="load"
                offset="20" :error.sync="error" error-text="请求失败，点击重新加载" :immediate-check="immediateCheck">

				<van-cell @click="toDetail(item.fdId,item.acceptType,item.uuid)"   center v-for="item in list" :title="item.title"  value-class="text-sm">
					<template #title>
						<span class="custom-title van-ellipsis">{{item.title}}</span>
					</template>

					<template #label>
						<view class="padding-xs text-gray">来电号：{{item.fdWord}}[{{item.fdYear}}]{{item.fdNum}}号</view>
						<view class="padding-xs text-gray  ">来电单位：{{item.sendDeptName}}</view>
					</template>
          <template #extra>
            <text class="text-blue">
              <i class="iconfont icon-dian text-blue"></i>{{item.acceptType == '1'?'已签':'待收'}}
            </text>
          </template>
				</van-cell>

			</van-list>
		</van-pull-refresh>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				emptyData:false,//是否显示暂无数据图片
				list: [],
				error: false,     // 错误状态
				loading: false,   // 加载状态
				finished: false,  // 是否加载
				refreshing: false,// 是否刷新
				pageNum: 1,   		// 页数
				pageSize: 10, 		// 条数
				immediateCheck: true, // 是否在初始化时立即执行滚动位置检查　　　
			}
		},
		methods: {
			// 下拉刷新
			onRefresh() {
				console.log('----------------onRefresh-->> ');
				// 先清空数据
				this.list = []
				// 将没有更多的状态改成false
				this.finished = false
				// 默认加载第一页
				this.pageNum = 1
				this.queryGwhgList()
				this.refreshing = false
			},
			load() {
				console.log('----------------load-->> ' + this.receType);
				// 页数设置
				if( this.list.length == 0){
					this.pageNum = 1
				} else {
					this.pageNum++
				}
				// 将下拉刷新停止
				this.refreshing = false;
				setTimeout(() => {
					this.queryGwhgList()
				}, 500)
			},
			//获取待收来电
			queryGwhgList(){
				// this.list=[]//清空静态数据
				this.loading = true
				this.$http({
				 url: this.$http.adornUrl(`/caac/oa/doc/hbglj/fdpengding/pengdinglist`),
				 method: 'get',
				 params: this.$http.adornParams({
					  'acceptType': 1,
					  'page': this.pageNum,
					  'rows': this.pageSize,
					  'systemKey': this.cache.get('userInfo').systemKey,//固定值
					  'systemFlag': this.cache.get('userInfo').systemFlag,//固定值
				 })
				}).then(({data}) => {
					console.log("待收来电：data: " + JSON.stringify(data));
					if(data.code==200){
						this.loading = false;
						if(this.pageNum == 1) {
							this.list = data.data.rows
						} else {
							data.data.rows.forEach( t => this.list.push(t))
						}
            if(this.list.length==0){
              this.emptyData = true
            }else{
              this.emptyData = false
            }
						// 判断当前页是否为最后一页
						if((this.pageNum*this.pageSize) > data.data.total) {
							this.finished = true
						}
					}else{
						this.error = true
						console.log("出错data: " + JSON.stringify(data));
					}
				}).catch((err) => {
					this.error = true
				}).finally(() => {
					// 关闭加载状态
					this.loading = false
				})
			},
			//acceptType:1-已签，0-待收
			toDetail(fdId,acceptType,uuid){
				uni.navigateTo({
					url:"/pages/jgj/receiveMsg/receive?fdId="+fdId+"&acceptType="+acceptType+"&uuid="+uuid
				})
			},
		},
	}
</script>

<style scoped>
	 .custom-title {
	    margin-left: 4rpx;
	    vertical-align: middle;
	  }
</style>
